<template>
  <div class="header">
    <div class="date">
      <span class="icon iconfont">&#xe8b4;</span>{{ state.date }}
    </div>
    <div class="page-tab">
      <dv-decoration-11 style="width: 200px; height: 50px">
        <span
          @click="switchTab('measure')"
          v-bind:class="{ active: state.curTab == 'measure' }"
          >图上量测</span
        >
      </dv-decoration-11>
    </div>
    <div class="page-tab">
      <dv-decoration-11
        style="width: 200px; height: 50px"
        @click="switchTab('mark')"
        >图上标绘</dv-decoration-11
      >
    </div>
    <div class="title">
      <div class="name">电子沙盘</div>
      <div style="display: flex; justify-content: space-between">
        <dv-decoration-8 style="width: 240px; height: 50px" />
        <dv-decoration-8 :reverse="true" style="width: 240px; height: 50px" />
      </div>
    </div>
    <div class="page-tab">
      <dv-decoration-11 style="width: 200px; height: 50px">
        <span
          @click="switchTab('weather')"
          v-bind:class="{ active: state.curTab == 'weather' }"
          >天气模拟</span
        >
      </dv-decoration-11>
    </div>
    <div class="page-tab">
      <dv-decoration-11 style="width: 200px; height: 50px">
        <span
          @click="switchTab('army')"
          v-bind:class="{ active: state.curTab == 'army' }"
          >军事标注</span
        >
      </dv-decoration-11>
    </div>
    <div class="date">小雨 19℃-25℃</div>
  </div>
  <div class="map-view" id="mapContainer"></div>
  <Measure ref="measure" />
  <Weather ref="weather" />
  <Army ref="army" />
  <Mark ref="mark" />
</template>

<script setup>
import { onMounted, onUnmounted, getCurrentInstance } from "vue";
import { saveMapClass } from "@/map/utils/mapCommon.js";
import { useRouter } from "vue-router";
import * as mars3d from "mars3d";
import "mars3d-space";
const Cesium = mars3d.Cesium;
import * as turf from "@turf/turf";
import Measure from "./views/measure/index.vue";
import Weather from "./views/weather/index.vue";
import Army from "./views/army/index.vue";
import Mark from "./views/mark/index.vue";
import Map from "@/map/index.js";
import dayjs from "dayjs";
import "dayjs/locale/zh-cn"; // 如果你希望以中文显示星期，可以引入中文语言包
import { clamp } from "lodash";
import config from "./map/config/index.json";
dayjs.locale("zh-cn"); // 设置 Day.js 使用的语言环境为中文
const { proxy } = getCurrentInstance();

const state = reactive({
  date: dayjs().format("YYYY-MM-DD dddd HH:mm:ss"),
  curTab: "measure",
});

const timer = setInterval(() => {
  state.date = dayjs().format("YYYY-MM-DD dddd HH:mm:ss");
}, 1000);

let map = null;
onMounted(() => {
  map = new Map("mapContainer", config, callbackOptions);
  saveMapClass(map);
  map.marsMap.setCameraView(
    {
      lng: 116.047056,
      lat: 23.931436,
      alt: 10000,
    },
    {
      duration: 0,
    }
  );
});

const callbackOptions = {
  getClickPosition: getClickPosition,
};
function getClickPosition(position) {
  console.log(position);
}
onUnmounted(() => {
  map.marsMap.destroy();
  map = null;
});
function switchTab(tabName) {
  proxy.$refs[state.curTab].isShow(false);
  proxy.$refs[tabName].isShow(true);
  state.curTab = tabName;
}
</script>

<style scoped lang="less">
.active {
  color: #409eff;
  font-weight: 800;
}

.header {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  justify-content: space-between;
  height: 80px;
  width: 100%;
  color: #fff;
  font-family: my-self-font;
  z-index: 100;

  .date {
    line-height: 80px;
    font-size: 14px;
  }

  .page-tab {
    line-height: 80px;
    font-size: 20px;
    // font-weight: 800;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    cursor: pointer;
    font-size: 16px;
  }

  .title {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: center;
    width: 500px;

    .name {
      height: 40px;
      line-height: 75px;
      font-size: 30px;
      font-weight: 600;
      letter-spacing: 6px;
    }
  }
}

.map-view {
  width: 100%;
  height: 100%;
}
</style>
